const input = [
    'sz000001',
    'sz000002',
    'sh600001',
    'sh600002',
    'sh600003',
];
// const input = [
//     ['sz', '000001'],
//     ['sz', '000001'],
//     ['sz', '000001'],
//     ['sz', '000001'],
//     ['sz', '000001'],
// ];

const output = {
    sz: ['000001', '000002'],
    sh: ['600001', '600002', '600003'],
};

function transform(input) {
    return input
        .map(item => [item.substr(0, 2), item.substr(2, 6)])
        .reduce((prev, [exchange, id]) => {
            // 1: prev: {  }  current: ['sz', '000001']
            // 2: prev: { sz: ['000001'] }  current: ['sz', '000002']
            // 3: prev: { sz: ['000001', '000002'] }  current: ['sh', '600001']
            // 4: prev: { sz: ['000001', '000002'], sh: ['600001'] }  current: ['sh', '600002']
            // 5: prev: { sz: ['000001', '000002'], sh: ['600001', '600002'] }  current: ['sh', '600003']
            // 6: result: { sz: ['000001', '000002'], sh: ['600001', '600002', '600003'] }
            if (!prev[exchange]) {
                prev[exchange] = [id];
            } else {
                prev[exchange].push(id);
            }
            return prev;
        }, {});
}

console.log(transform(input));
